//根据CODE查询部门
import {
  uncompileStr,
  VerifySessionTime,
  compileStrCop,
  findConfig,
  compileStr,
  getHeaderParams,
  getResponseUrl,
  getLinkToUrl,
  devProTest,
  frontUrlTest,
} from '../rudexRou/OperatesCookie.js';
export const getDeptByCode = (code) => {
  const deptList = localStorage.getItem('deptList')
    ? JSON.parse(localStorage.getItem('deptList'))
    : [];
  let label;
  function searchCode(obj) {
    for (const a in obj) {
      if (obj[a].value == code) {
        label = obj[a].label;
        return;
      }
      if (typeof obj[a] == 'object') searchCode(obj[a]);
    }
  }
  searchCode(deptList);
  return label;
};

// 根据编码确定查询的部门
export const confirmDeptByCode = (code) => {
  const deptList = localStorage.getItem('deptList')
    ? JSON.parse(localStorage.getItem('deptList'))
    : [];
  let result;
  function searchCode(obj) {
    for (const a in obj) {
      if (obj[a].value == code) {
        result = obj[a];
        return;
      }
      if (typeof obj[a] == 'object') searchCode(obj[a]);
    }
  }
  searchCode(deptList);
  return result;
};
export const checkAllNumber = (str) => {
  var regPos = /^\d+(\.\d+)?$/; //非负浮点数
  if (regPos.test(str)) {
    return true;
  } else {
    return false;
  }
};

export const getUrl = (url) => {
  // console.log(window.location.origin);
  let hash = window.location.hash.split('&');
  hash.splice(0, 1);
  let search = '/&' + hash.join('&');
  window.location.href =
    getLinkToUrl('platform') + '/TmfsExam/#' + url + search;
};
